﻿Imports System.Collections.Generic

Partial Class WebForm_SearchTrainingCourseControl
    Inherits System.Web.UI.UserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

#Region "Delegate"

    Public Event OK_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    Protected Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click
        'GridView_TrainingCourse.DataSourceID = ""
        RaiseEvent OK_Click(Me, New EventArgs)
    End Sub

#End Region

    Protected Sub GridView_TrainingCourse_PageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView_TrainingCourse.PageIndexChanged
        Me.mpSearch.Show()
    End Sub

    Protected Sub GridView_TrainingCourse_Sorted(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView_TrainingCourse.Sorted
        Me.mpSearch.Show()
    End Sub

End Class

Partial Class WebForm_SearchTrainingCourseControl

    Public Sub InitDataAndShow()

        ObjectDataSource1.SelectParameters("GroupId").DefaultValue = GroupId
        ObjectDataSource1.SelectParameters("CourseType").DefaultValue = Me.CourseType
        GridView_TrainingCourse.DataSourceID = ObjectDataSource1.ID
        GridView_TrainingCourse.DataBind()
        Me.mpSearch.Show()

    End Sub

#Region "Property"

    Public ReadOnly Property SelectedValues() As List(Of String)
        Get
            Dim TrainingCourses As New List(Of String)

            For Each row As GridViewRow In Me.GridView_TrainingCourse.Rows
                Dim key As DataKey = Me.GridView_TrainingCourse.DataKeys(row.RowIndex)

                If TryCast(row.FindControl("CheckBox1"), CheckBox).Checked = True Then
                    TrainingCourses.Add(key("Id"))
                End If
            Next

            Return TrainingCourses
        End Get
    End Property

    Public Property GroupId() As String

        Get
            Return ViewState("GroupId").ToString()
        End Get
        Set(ByVal value As String)
            ViewState("GroupId") = value
        End Set

    End Property

    Public Property CourseType() As String

        Get
            Return ObjectDataSource1.SelectParameters.Item("CourseType").DefaultValue
        End Get
        Set(ByVal value As String)
            ObjectDataSource1.SelectParameters.Item("CourseType").DefaultValue = value
        End Set

    End Property





#End Region

End Class
